home *** CD-ROM | disk | FTP | other *** search
- Path: news.staffs.ac.uk!bs47c!cm4bctrd
- From: cm4bctrd@bs47c.staffs.ac.uk (Wildfire)
- Newsgroups: comp.lang.c
- Subject: Re: Q: realloc->free?
- Date: 15 Jan 1996 19:12:31 GMT
- Organization: Staffordshire University
- Message-ID: <4de8uv$48j@bs33n.staffs.ac.uk>
- References: <4daa2e$oh5@axe.netdoor.com>
- NNTP-Posting-Host: bs47c.staffs.ac.uk
- X-Newsreader: TIN [version 1.2 PL2]
-
- On Sun, 14 Jan 1996 07:08:29 GMT, Eric Sargent looked thoughtfully at the keyboard and typed...
- : This is probably a dumb question, but I can't find any specific or
- : exact information about this. Given this:
-
- : char *a, *b;
-
- : a = malloc(10);
- : ...
- : /*
- : later we need to increase the size
- : */
- : ...
- : b = realloc(a, 100);
-
- : Now let's say realloc had to move the data so a != b. Does realloc
- : free the memory previously pointed to by a or should it be explicitly
- : freed if realloc returns a new location? I checked the FAQ, but there
- : was nothing specific about realloc. Thanks for any information.
-
- Right. I could be wrong in what I'm about to say, but I *think* this is
- correct.
-
- If you think about it, there is no need for realloc() to move the *start*
- of the allocated memory - it may need to make a link between the end of
- the original memory block and the start of an extension block, but that's
- different.
-
- So b is either going to be NULL or a.
-
- realloc() does no free()ing, as far as I know, since the contents of
- memory are unchanged.
-
- I would really like someone who properly knows about this to confirm or
- correct what I'm saying.
-
- Wildfire :-)
-
- -----------------------------------------------------------------------------
- "Oh God could it be the weather? - oh God - why am I here? If love isn't
- forever...and it's not the weather...*whisper* - hand me my leather..."
-
- Member of the AEL fan club :-)
-
- Knight of The Rose, loyal follower of The Sea...(mud.veda.is 4000)
- -----------------------------------------------------------------------------
-